package ooday03exercise;

import ooday03exercise.Master;

public class PolymorphicDemo {
    public static void main(String[] args) {
        Animal[] animals= new Animal[3];
        animals[0] = new Dog("小黑",2,"白");
        animals[1] = new Chick("小灰",1,"灰白");
        animals[2] = new Fish("小绿",3,"银白");
        for (int i=0;i<animals.length;i++){

            System.out.println(animals[i].name+animals[i].color);
            animals[i].drink();
            animals[i].eat();
            if(animals[i] instanceof Dog){
                Dog d = (Dog) animals[i];
                d.lookHome();
            }
            if (animals[i] instanceof Chick){
                Chick c = (Chick) animals[i];
                c.layEgg();
            }
            if (animals[i] instanceof Swim){
                Swim s = (Swim) animals[i];
                s.swim();
            }
        }
        Master master= new Master();
        Dog dog = new Dog("小七",2,"斑白");
        Chick chick= new Chick("小八",1,"绿白");
        Fish fish = new Fish("小九",3,"黑白");
        master.feed(dog);
        master.feed(chick);
        master.feed(fish);
    }
}
